version: "3.7"

networks:
  backend-network:
    driver: bridge
    ipam:
      config:
        - subnet: ${BACKEND_SUBNET}
  frontend-network:
    driver: bridge
    ipam:
      config:
        - subnet: ${FRONTEND_SUBNET}

services:
  postgres:
    container_name: lnpp-postgres
    build:
      context: ./postgres
      dockerfile: Dockerfile
    working_dir: /var/lib/postgres
    restart: unless-stopped
    ports:
      - "5432:5432"
    volumes:
      - ${HOST_STORAGE_PATH}/postgres:/var/lib/postgresql/data
      - ${HOST_LOG_PATH}/postgres:/var/log/postgresql
    networks:
      backend-network:
        ipv4_address: ${POSTGRES_IP}
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  php-fpm:
    container_name: lnpp-php
    build:
      context: ./php-fpm
      dockerfile: Dockerfile
    working_dir: /var/www
    restart: unless-stopped
    ports:
      - "9000:9000"
    expose:
      - "9003"
    volumes:
      - ${HOST_CODE_PATH}:/var/www
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      - XDEBUG_MODE=develop,debug
    networks:
      backend-network:
        ipv4_address: ${PHPFPM_IP}
    depends_on:
      - postgres

  nginx:
    container_name: lnpp-nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
    working_dir: /var/www
    restart: unless-stopped
    ports:
      - "81:81"
      - "82:82"
    volumes:
      - ${HOST_CODE_PATH}:/var/www
      - ${HOST_LOG_PATH}/nginx:/var/log/nginx
    networks:
      backend-network:
        aliases:
          - site01.test
        ipv4_address: ${NGINX_BACKEND_IP}
      frontend-network:
        aliases:
          - site02.test
        ipv4_address: ${NGINX_FRONTEND_IP}
    depends_on:
      - postgres
      - php-fpm
